/* gcc sock_c.c -l wsock32 -o cli.exe */
#include <Winsock2.h>
#include <stdio.h>
int main(){
	WORD wVersionRequested;
	WSADATA wsaData;
	int err = 0 ;
	
	wVersionRequested = MAKEWORD( 2, 2 );
	
	err = WSAStartup( wVersionRequested, &wsaData );
	if( err != 0 ){
		return -1;
	}
	
	if( LOBYTE( wsaData.wVersion ) != 2 || HIBYTE( wsaData.wVersion ) != 2 ){
		WSACleanup( );
		return -1;
	}

	SOCKADDR_IN addrSrv;
	addrSrv.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
	addrSrv.sin_family = AF_INET;
	addrSrv.sin_port = htons(6000);
	int len = sizeof(SOCKADDR);
	while(1){
		SOCKET sockClient = socket(AF_INET, SOCK_STREAM, 0);
		connect(sockClient, (SOCKADDR*)&addrSrv, len);

		char recvBuf[100];
		recv(sockClient, recvBuf, 100, 0);
		printf("%s\n", recvBuf);
		
		printf("input your message:");
		char temp[100];
		scanf("%s", temp);
		send(sockClient, temp, strlen(temp)+1, 0);

		closesocket(sockClient);
		//WSACleanup();
	}
	return 0;
}
